fix(ci): add missing src/alpaca_account_lock and src/trading_server modules#79
fix(ci): add missing src/alpaca_account_lock and src/trading_server modules#79
Conversation
…odules The fast-unit-tests CI job was failing with: ModuleNotFoundError: No module named 'src.alpaca_account_lock' trade_daily_stock_prod.py imports `acquire_alpaca_account_lock` and `require_explicit_live_trading_enable` from `src.alpaca_account_lock` at module level. pytest failed to collect tests/test_trade_daily_stock_prod.py because this module did not exist, causing the entire test run to abort. Additionally, trade_daily_stock_prod.py imports `TradingServerClient` from `src.trading_server.client` at module level (next import after the one that was failing). Created the full trading_server package to prevent a second collection error. Changes: - src/alpaca_account_lock.py: advisory file-lock + live-trading guardrail - src/trading_server/__init__.py: package init - src/trading_server/client.py: HTTP REST client (TradingServerClient) - src/trading_server/server.py: in-process paper trading engine (TradingServerEngine) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Codex Infinity Start a task on this PR's branch by commenting:
Tasks and logs: https://codex-infinity.com |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 29a5b5d801
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| state = self._get_account(account) | ||
| state.writer_bot_id = bot_id | ||
| state.writer_session_id = session_id |
There was a problem hiding this comment.
Enforce exclusive writer claims per account
claim_writer currently just overwrites writer_bot_id/writer_session_id and always returns success, so a second process can claim the same account immediately after the first one and both will believe they have exclusive write access. In concurrent runs (the exact scenario this API is meant to guard), this allows conflicting order flows and breaks the intended single-writer safety guarantee.
Useful? React with 👍 / 👎.
| "id": order_id, | ||
| "symbol": symbol, | ||
| "side": side, | ||
| "qty": qty, |
There was a problem hiding this comment.
Record filled sell quantity instead of requested size
The order record stores qty from the request even though sell execution may be capped to the held position (sell_qty = min(qty, existing_qty)). When callers submit a sell larger than holdings, history reports a larger filled size than what was actually executed, which can corrupt downstream reconciliation and analytics based on order_history.
Useful? React with 👍 / 👎.
Summary
fast-unit-testsCI job was aborting with a collection error:ModuleNotFoundError: No module named 'src.alpaca_account_lock'trade_daily_stock_prod.pyimportsacquire_alpaca_account_lockandrequire_explicit_live_trading_enablefromsrc.alpaca_account_lockat module level (line 36)tests/test_trade_daily_stock_prod.pybecause this module did not exist, causing the entire test run to abort with exit code 2from src.trading_server.client import TradingServerClient, line 37) would have caused a second collection error once the first was fixedChanges
src/alpaca_account_lock.py– advisory file-lock (acquire_alpaca_account_lock) and live-trading guardrail (require_explicit_live_trading_enable) following the same pattern asbagsfm/utils.py::require_live_trading_enabledsrc/trading_server/__init__.py– package initsrc/trading_server/client.py– HTTP REST client (TradingServerClient) wrapping the trading server APIsrc/trading_server/server.py– in-process paper trading engine (TradingServerEngine) for deterministic backtests, matching the interface used byInMemoryTradingServerClientintrade_daily_stock_prod.pyTest plan
src.alpaca_account_lockimports successfullysrc.trading_server.client.TradingServerClientimports successfullysrc.trading_server.server.TradingServerEngineimports successfullyfast-unit-testsjob collectstests/test_trade_daily_stock_prod.pywithout error🤖 Generated with Claude Code